﻿using System.Data;
using ET;
using System.Data.SqlClient;
namespace DAL
{
    public class Order_DAL : clsConnect
    {
        private static readonly clsConnect cls = new clsConnect();
        #region[Get-Data]
        public DataTable GetOrder(string keywords)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@KEYWORDS", keywords);
            return cls.GetData("sp_tb_Order_Search");
        }
        public DataTable GetOrderIsUsed(string keywords)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@KEYWORDS", keywords);
            return cls.GetData("sp_tb_Order_IsUsed");
        }
        public DataTable GetOrderOrder()
        {
            cls.CreateNewSqlCommand();
            return cls.GetData("sp_tb_Order_Buy_Order");
        }
        public DataTable GetOrderDetail_Edit(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", id);
            return cls.GetData("sp_tb_Order_Edit");
        }
        public DataTable GetCodeOrder()
        {
            return cls.GetData("sp_tb_Order_CreateCode");
        }
        public static DataTable GetOrderActive(string keywords, int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@KEYWORDS", keywords);
            cls.AddParameter("@IsActive", id);
            return cls.GetData("sp_tb_Order_Fillter");
        }
        public static DataTable GetOrderFillterDate(string DateBegin, string DateEnd)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@DateBegin", DateBegin);
            cls.AddParameter("@EndBegin", DateEnd);
            return cls.GetData("sp_tb_Order_FillterDate");
        }
        #endregion

        #region[Insert-Update-Delete]
        //public bool Inserttb_Order(Order_ET data)
        //{
        //    var cmd = new SqlCommand
        //    {
        //        Connection = GetConnection(),
        //        CommandType = CommandType.StoredProcedure,
        //        CommandText = "sp_tb_Order_Insert"
        //    };

        //    cmd.Parameters.Add("@Order_Code", SqlDbType.NVarChar).Value = data.Order_Code;
        //    cmd.Parameters.Add("@Order_TaxCode", SqlDbType.NVarChar).Value = data.Order_TaxCode;
        //    cmd.Parameters.Add("@Order_Date", SqlDbType.DateTime).Value = data.Order_Date;
        //    cmd.Parameters.Add("@Customer_Id", SqlDbType.Int).Value = data.Customer_Id;
        //    cmd.Parameters.Add("@Order_DateBegin", SqlDbType.DateTime).Value = data.Order_DateBegin;
        //    cmd.Parameters.Add("@Order_DateEnd", SqlDbType.DateTime).Value = data.Order_DateEnd;
        //    cmd.Parameters.Add("@Order_Payment_Date", SqlDbType.DateTime).Value = data.Order_Payment_Date;
        //    cmd.Parameters.Add("@Order_Transport", SqlDbType.Float).Value = data.Order_Transport;
        //    cmd.Parameters.Add("@Order_Note", SqlDbType.NVarChar).Value = data.Order_Note;

        //    cmd.Parameters.Add("@Order_VAT", SqlDbType.Float).Value = data.Order_VAT;
        //    cmd.Parameters.Add("@Order_Total", SqlDbType.Float).Value = data.Order_Total;
        //    cmd.Parameters.Add("@Order_Total_Payment", SqlDbType.Float).Value = data.Order_Total_Payment;
        //    cmd.Parameters.Add("@IsActive", SqlDbType.Bit).Value = data.IsActive;
        //    cmd.Parameters.Add("@Users_Id", SqlDbType.Int).Value = data.Users_Id;
        //    cmd.Parameters.Add("@Order_Id", SqlDbType.Int).Direction = ParameterDirection.Output;
        //    cmd.ExecuteNonQuery();
        //    data.Order_Id = int.Parse(cmd.Parameters["@Order_Id"].Value.ToString());
        //    return true;
        //}
        //public bool Updatetb_Order(Order_ET data)
        //{
        //    cls.CreateNewSqlCommand();
        //    cls.AddParameter("@Order_Id", data.Order_Id);
        //    cls.AddParameter("@Order_TaxCode", data.Order_TaxCode);
        //    cls.AddParameter("@Order_Note", data.Order_Note);
        //    return cls.ExecuteNonQuery("sp_tb_Order_Update");
        //    return true;
        //}
        //public bool Updatetb_OrderIsUsed(Order_ET data)
        //{
        //    cls.CreateNewSqlCommand();
        //    cls.AddParameter("@Order_Id", data.Order_Id);
        //    cls.AddParameter("@IsUsed", data.IsUsed);
        //    return cls.ExecuteNonQuery("sp_tb_Order_Update_IsUsed");
        //    return true;
        //}
        //public bool Delete_Order(int id)
        //{
        //    cls.ExecuteNonQuery("sp_tb_Order_Delete", "@Order_Id", id);
        //    return true;
        //}
        //public bool Delete_OrderStatics(int id)
        //{
        //    cls.ExecuteNonQuery("sp_tb_Order_Statics_Delete", "@Order_Id", id);
        //    return true;
        //}
        #endregion

        #region[Search-Fillter]
        public DataTable SearchOrder(string keywords)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@KEYWORDS", keywords);
            return cls.GetData("sp_tb_Order_Search");
        }
        #endregion

        #region[Check-Del]
        public bool CheckDelOrder(int id)
        {
            DataTable dtCheckDel;
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", id);
            dtCheckDel = cls.GetData("sp_Order_Buy_Check_Delete_tb_Order");
            if (dtCheckDel.Rows.Count > 0)
                return true;
            return false;
        }
        #endregion
    }
}